@extends('layouts.default') @section('main')
    <link rel="stylesheet" href="{{URL::asset('js/')}}/kindeditor-4.1.7/themes/default/default.css" />
    <link rel="stylesheet" href="{{URL::asset('js/')}}/kindeditor-4.1.7/plugins/code/prettify.css" />
    <script src="{{URL::asset('js/')}}/kindeditor-4.1.7/kindeditor.js" type="text/javascript"></script>
    <script charset="utf-8" src="{{URL::asset('js/')}}/kindeditor-4.1.7/lang/zh_CN.js"></script>
    <script charset="utf-8" src="{{URL::asset('js/')}}/kindeditor-4.1.7/plugins/code/prettify.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/ajaxfileupload.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>
    <script>
        KindEditor.ready(function(K) {

            var editor1 = K.create('#notice_content', {
                uploadJson: "{{url('kindedit/upload')}}",
                fileManagerJson: "{{url('kindedit/manager')}}",
                allowFileManager: true,
                afterBlur: function() {
                    this.sync();
                },
                items: ['source', '|', 'undo', 'redo', '|', 'cut', 'copy', 'paste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', 'image', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink', '|']
            });

        });
    </script>
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
                            class="icon-home"></i> 首页</a>
                <a href="{{url('project/index')}}" class="tip-bottom">项目管理</a>
                <a href="#" class="current">新增一个推荐方</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span9">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
                            <h5>新增一个推荐方</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form action="{{url('project/edit-rec')}}" id="adForm" method="post" class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>是否已经为会员 :</label>
                                    <div class="controls">
                                        <select  name="type" class=" span11" >
                                            <option value="" >请选择</option>
                                            <option value="1" >是</option>
                                            <option value="0" >不是</option>
                                        </select>
                                    </div>
                                </div>
                                <div id="user" style="display: none">
                                    <div class="control-group">
                                        <label class="control-label">用户手机号的一部分供模糊搜索 :</label>
                                        <div class="controls">
                                            <input type="text" class="span11" name="user_search" value="" placeholder="输入用户手机号的一部分，按下Enter键，搜索结果将出现在下面的多选框中，供选择" />
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label class="control-label"><span class="redD">*</span>会员username :</label>
                                        <div class="controls">
                                            <select name="uid" id="uid">
                                                <option value="0">请选择</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">头像 :</label>
                                    <div class="controls">
                                        <input type="hidden" class="span11" name="avatar" value="{{$list->avatar}}"
                                               placeholder="点击右边小图标上传" />
                                        <img src="{{getImage($list->avatar)}}" width="120px" id="avatar" name="avatar" height="120px"/>

                                        <a href="javascript:void(0);" id="uploadWxphotoBtn"   onclick="javascript:openBrowse('uploadWxphotoBtn','uploadWxphoto');">点击上传</a>
                                        <input type="file" id="uploadWxphoto" style="display:none" name="myfile" size="10" onchange="fileUpload('uploadWxphoto','avatar')"/>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>名字 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="name" placeholder="名字" value="{{$list->name}}" />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">职位 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="position" value="职位" value="{{$list->position}}" />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label"><span class="redD">*</span>描述 :</label>
                                    <div class="controls">
                                        <textarea id="notice_content" name="description" style="width: 450px; height: 240px;">{{$list->description}}</textarea>
                                    </div>
                                </div>

                                <input type="hidden" class="span11" name="formType" value="edit" />
                                <div class="form-actions">
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                    <input type="hidden" name="project_id" value="{{$list->project_id}}">
                                    <input type="hidden" name="id" value="{{$list->id}}">
                                    <button type="button" id="doSave" class="btn btn-success">编辑</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        //初始化
        var receiver = $('select[name=receiver]').val();
        if(receiver=='single'){
            $('#phone').show();
        }

        //发送者变化时，显示或隐藏
        $('select[name=receiver]').change(function(){
            var receiver = $('select[name=receiver]').val();
            if(receiver=='single'){
                $('#phone').show();
            }else{
                $('#phone').hide();
            }
        });

        $("#doSave").click(function(){
            ajaxRequest($('#adForm').serializeArray(),$('#adForm').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });



        $("input[name='user_search']").keydown(function(event) {
            if (event.which == "13"){
                var param = {};
                param['user_search'] = $(this).val();
                ajaxRequest(param, '/project/user-search', function (data) {
                    if (data.status) {
                        var html = '<option value="">请选择</option>';
                        $.each(data.message, function (i, n) {
                            html += "<option value='" + n.uid + "'>" + n.username + "</option>";

                        });
                        $("#uid").html(html);
                        alert('恭喜，已经生成选项,请选择所需要的用户');
                    } else {
//                        var html = '<option value="">请按上面输入框的说明生成选项</option>';
//                        $("#post_id").html(html);
                        alert(data.message);
                    }
                });
            }
        });

        $("select[name='uid']").change(function(){
            var val = $("select[name='uid']").val();
            var param = {};
            param['uid'] = val;
            ajaxRequest(param, '/project/search-user', function (data) {
                if (data.status) {
                    if(data.message.realname){
                        var name = data.message.realname;
                    }else{
                        name = data.message.nickname;
                    }
                    var job = data.message.user_info.job;
                    var avatar = data.message.avatar;
                    param['avatar'] = avatar;

                    ajaxRequest(param, '/project/image', function (datas) {
                        $("#avatar").attr('src',datas.message);
                    });

                    $("input[name='name']").val(name);
                    $("input[name='position']").val(job);
                    $("input[name='avatar']").val(avatar);

                } else {
//                    alert(data.message);
                }
            });
        });
        $("select[name='type']").change(function(data){
            var val = $(this).val();
            if(1==val){
                $("#user").show();
            }else{
                $("#user").hide();
            }
        })
    </script>
@stop
